/*
 *             Copyright (C) 2024 Steve Jrong
 *
 * 	   GitHub Homepage: https://www.github.com/SteveJrong
 *      Gitee Homepage: https://gitee.com/stevejrong1024
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.stevejrong.waiter.rp.domainservice.factory;

import java.util.List;

import com.google.common.collect.Lists;
import com.stevejrong.waiter.rp.dbsdk.model.MerchantUserPermissionBackendPermPO;
import com.stevejrong.waiter.rp.model.aggregates.MerchantUserPermission;
import com.stevejrong.waiter.rp.model.valueobjects.Status;

import lombok.NoArgsConstructor;

/**
 * 聚合工厂 - 商家用户权限
 *
 * @author Steve Jrong
 * @since 1.0
 */
@NoArgsConstructor
public final class MerchantUserPermissionFactory {

    /**
     * 单个PO转为单个DO
     *
     * @param merchantUserPermissionBackendPermPO 商家用户权限的数据持久化对象
     * @return 商家用户权限的领域对象
     */
    public static MerchantUserPermission getDomainObjectFromPO(MerchantUserPermissionBackendPermPO merchantUserPermissionBackendPermPO) {
        MerchantUserPermission merchantUserPermission = new MerchantUserPermission();

        merchantUserPermission.setId(merchantUserPermissionBackendPermPO.getId());
        merchantUserPermission.setCreateAt(merchantUserPermissionBackendPermPO.getCreateAt());
        merchantUserPermission.setUpdateAt(merchantUserPermissionBackendPermPO.getUpdateAt());
        merchantUserPermission.setName(merchantUserPermissionBackendPermPO.getName());
        merchantUserPermission.setDescription(merchantUserPermissionBackendPermPO.getDescription());
        merchantUserPermission.setPermUrl(merchantUserPermissionBackendPermPO.getPermUrl());
        merchantUserPermission.setPermCode(merchantUserPermissionBackendPermPO.getPermCode());
        merchantUserPermission.setStatus(Status.getEnumByOriginalVal(merchantUserPermissionBackendPermPO.getStatus()));

        return merchantUserPermission;
    }

    /**
     * PO集合转DO集合
     *
     * @param merchantUserPermissionBackendPermPOs 商家用户权限的数据持久化对象集合
     * @return 商家用户权限的领域对象集合
     */
    public static List<MerchantUserPermission> getDomainObjectsFromPOs(List<MerchantUserPermissionBackendPermPO> merchantUserPermissionBackendPermPOs) {
        List<MerchantUserPermission> merchantUserPermissions = Lists.newArrayList();

        for (MerchantUserPermissionBackendPermPO item : merchantUserPermissionBackendPermPOs) {
            merchantUserPermissions.add(getDomainObjectFromPO(item));
        }

        return merchantUserPermissions;
    }
}